package org.longsheng.GroovyLearn.java.aop;

import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;

import java.util.ArrayList;
import java.util.List;

@Slf4j
public class WordImpl implements Word{

    private static List<String> keyWordList = new ArrayList<>();

    @Override
    public void addWord(String word) {
        if (keyWordList.contains(word)) {
            return;
        }

        keyWordList.add(word);
    }

    @Override
    public List<String> findKeyword(String content) {
        List<String> resultList = new ArrayList<>();
        if (StringUtils.isEmpty(content)) {
            return resultList;
        }

        for (String word : keyWordList) {
            if (content.indexOf(word) > -1) {
                resultList.add(word);
            }
        }

        // log.info("日志：{} - {}", content, resultList);

        return resultList;
    }
}
